<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Mr_kelas extends CI_Controller {

	function __construct() {
        parent::__construct();
        $this->isLogin();	
		$this->load->model("master/master_kelas"); 	
		$this->num_post = 10;	
	}

	function isLogin(){
		$login=$this->session->userdata('isLogin');
		if(! isset($login)||$login != true){
			$this->session->set_flashdata('error_login', 'Untuk Mengakses Admin Anda Harus Login!');
			redirect('login');	
		}
	}
	
	function index($offset = 0)
	{
		$data['main_view']='master/mr_kelas/read';

		$uri_segment = 3;
		
		if($offset != 0){
			$offset = $this->uri->segment($uri_segment);
		}else{
			$offset=$offset;
		}
		$data['list'] = $this->master_kelas->limit($this->num_post, $offset);
		$data['offset']=$offset;
		$num_rows = $this->master_kelas->num_rows();
			
		if($num_rows>0){
			// Membuat pagination
			$config['base_url'] = base_url().'mr_kelas/index';
			$config['cur_tag_open'] = '<li class=active><a href="#">';
			$config['cur_tag_close'] = '<span class="sr-only">(current)</span></a></li>';
			$config['num_tag_open'] = '<li>';
			$config['num_tag_close'] = '</li>';
			$config['prev_link'] = '<';
			$config['prev_tag_open'] = '<li>';
			$config['prev_tag_close'] = '</li>';
			$config['next_link'] = '>';
			$config['next_tag_open'] = '<li>';
			$config['next_tag_close'] = '</li>';
			//buat last
			$config['last_tag_open'] = '<li>';
			$config['last_tag_close'] = '</li>';
			$config['last_link'] = '>>';
			//buat first
			$config['first_tag_open'] = '<li>';
			$config['first_tag_close'] = '</li>';
			$config['first_link'] = '<<';
			$config['total_rows'] = $num_rows;
			$config['per_page'] = $this->num_post;
			$config['uri_segment'] = $uri_segment;
			$this->pagination->initialize($config);
			$data['pagination'] = $this->pagination->create_links();
		}

		$this->load->view('index',$data);
		
	}		
	
	function add()
	{
		$data['main_view']='master/mr_kelas/add';
		$this->load->view('index',$data);
	}
	
	function add_exe()
	{
		$dataInsert = array(
			'kelas' => $this->input->post('kelas')
		);
		$this->master_kelas->add($dataInsert);		
		redirect ('mr_kelas');
	}	
	
	function edit()
	{
		$id_mr_kelas = $this->security->xss_clean($this->uri->segment(3));	
		$data['list']=$this->master_kelas->edit($id_mr_kelas);		
		$data['main_view']='master/mr_kelas/edit';
		$this->load->view('index',$data);
	}
	
	function update()
	{
		$id_mr_kelas=$this->input->post('id_mr_kelas');		
		$dataUpdate=array(
			'kelas' => $this->input->post('kelas')
		);
		$this->master_kelas->update($id_mr_kelas,$dataUpdate);
		redirect('mr_kelas');
	}	
	
	function delete()
	{
		$id_mr_kelas = $this->security->xss_clean($this->uri->segment(3));
		$this->master_kelas->delete($id_mr_kelas);
		redirect('mr_kelas');
	}
	
}